package com.budwk.app.sqfw.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

/**
 * 天然气使用情况(无、使用醇基燃料、瓶装液化气、瓶装天然气、瓶装二甲醚、用电)
 */
@Getter
public enum NaturalGas {
    YHQ(1, "瓶装液化气"),
    TRQ(2, "瓶装天然气"),
    RJM(3, "瓶装二甲醚"),
    CJ(4, "使用醇基燃料"),
    YD(5, "用电"),
    N(6, "无");

    private Integer code;
    private String name;

    NaturalGas(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 通过code获取登录客户端类型
     * @param code
     * @return
     */
    public static String getName(Integer code) {
        for (NaturalGas o : NaturalGas.values()) {
            if (o.getCode() == code) {
                return o.getName();
            }
        }
        return null;
    }

    /**
     * 转string
     * @return
     */
    public static String getToString() {
        StringBuffer stringBuffer = new StringBuffer();
        for (NaturalGas o : NaturalGas.values()) {
            stringBuffer.append(o.getCode()).append("、").append(o.getName()).append(" ");
        }
        return stringBuffer.toString();
    }

    public static String getCode(String value) {
        if (StrUtil.isBlankIfStr(value)) return null;
        StringBuffer stringBuffer = new StringBuffer();
        for (NaturalGas o : NaturalGas.values()) {
            if (value.contains(o.getName())) stringBuffer.append(o.getCode()).append("、");
        }
        if (stringBuffer.length() == 0) return null;
        return stringBuffer.substring(0, stringBuffer.lastIndexOf("、"));
    }
}
